package com.hq.bootdemo.controller;

import com.hq.bootdemo.entity.TypeEntity;
import com.hq.bootdemo.service.TypeService;
import com.hq.bootdemo.util.JSONUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/type")
public class TypeController {
    @Resource
    TypeService typeService;
    @GetMapping("/selectAll")
    public String selectAll(String condition){
        List<TypeEntity> lists = typeService.selectAll(condition);
        String json = JSONUtil.getJson(lists);
        return json;
    }

    @PostMapping("/insertOne")
    public Boolean insertOne(TypeEntity typeEntity){

        return typeService.insertOne(typeEntity);
    }

    @PostMapping("/delOne")
    public boolean delOne(Integer id){
        return typeService.delOne(id);
    }

    @GetMapping("/selectOne")
    public String selectOne(Integer id){
       TypeEntity type = typeService.selectOne(id);
        String json = JSONUtil.getJson(type);
        return json;
    }
    @PostMapping("/update")
    public boolean update(TypeEntity type){
        return typeService.update(type);
    }
}
